'use strict'

const { DataTypes, Model } = require('../../azeroth').sequelize;
const { db_config } = require('../config.json');
const seq = require('../db/db').getSequelizeInstance(db_config);
// const seq = 
class Register extends Model { }


Register.init(
    {
        id: {
            autoIncrement: true,
            type: DataTypes.INTEGER,
            allowNull: false,
            primaryKey: true
        },
        username: {
            type: DataTypes.STRING,
            allowNull: true,
        },
        password: {
            type: DataTypes.STRING,
            allowNull: true,
        },
        phone: {
            type: DataTypes.STRING,
            allowNull: true,
        },
        address: {
            type: DataTypes.STRING,
            allowNull: true,
        },
        sex: {
            type: DataTypes.STRING,
            allowNull: true,
        },
        avator: {
            type: DataTypes.STRING,
            allowNull: true,
        }
    },
    {
        sequelize: seq,
        modelName: 'users',
        timestamps: false
    }
)

Register.createUser = async (data) => {
    let res = await Register.create(data);
    return res;
}

Register.getmaxId = async () => {
    let res = await seq.query(`select max(id) as id from users`, { type: seq.QueryTypes.SELECT });
    return res.length ? res[0].id : 1;
}


module.exports = {
    Register
};